package cn.edu.cjw.APMFP.ui.table;


import cn.edu.cjw.APMFP.user.pojo.User;
import javax.swing.table.AbstractTableModel;
import java.util.List;

public class UserTableModel extends AbstractTableModel{

	/**
	 *
	 */
	private static final long serialVersionUID = 1L;

	private List<User> list;
    private String[] columns = { "账号", "名称", "性别", "年龄", "状态"};

	public UserTableModel(List<User> list) {
		super();
		this.list = list;
	}

	@Override
	public int getRowCount() {
		return list.size();
	}

	@Override
	public int getColumnCount() {
		return columns.length;
	}
	
	@Override
	public String getColumnName(int column) {
		return columns[column];
	}
	
	private Object getColumn(User entity, int n) {
        switch (n) {
            case 0: return entity.getAccount();
            case 1: return entity.getName();
            case 2: return entity.getGender();
			case 3: return entity.getAge();
			case 4: return entity.isDeactivate() ? "停用" : "正常";
            default: return null;
        }
    }

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		return getColumn(list.get(rowIndex), columnIndex);
	}

}
